package com.lifupeng.learn.alibaba.cloud.order.controller;

import com.lifupeng.learn.alibaba.cloud.common.feign.OrderFeign;
import com.lifupeng.learn.alibaba.cloud.order.stream.OutputMessageBinding;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lifupeng.learn.alibaba.cloud.common.vo.Result;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @Author FuPeng Li
 * @Date 2021/8/12
 **/
@Api(tags = "测试模块",value = "测试模块")
@RestController
@RequestMapping("/order")
public class OrderController implements OrderFeign {

    @Autowired
    private OutputMessageBinding outputMessageBinding;

    @Override
    @ApiOperation("测试接口")
    @ApiImplicitParam(name = "id",value = "id")
    @PostMapping("/test")
    public Result test(@RequestBody String id){
        return Result.OK(id);
    }

    @ApiOperation("MQ测试接口")
    @ApiImplicitParam(name = "message",value = "消息")
    @PostMapping("/messageTest")
    public Result messageTest(String message){
        outputMessageBinding.output().send(MessageBuilder.withPayload(message).build());
        return Result.OK();
    }

    @ApiOperation("测试接口1")
    @ApiImplicitParam(name = "id",value = "id")
    @PostMapping("/test1")
    public Result test1(String id){
        Map map = new HashMap<>();
        map.put("order.test1",id);
        return Result.OK(map);
    }
}
